<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ES9正则扩展</title>
</head>

<body>

    <script>
        //声明字符串
        // let str = 'JS5211314你知道么555啦啦啦';
        //正向断言(根据想要匹配的后面的内容来判断前面的是否合法)
        // const reg = /\d+(?=啦)/;
        // const result = reg.exec(str)
        // console.log(result);

        //反向断言
        // const reg = /(?<=么)\d+/;
        // const result = reg.exec(str);
        // console.log(result);

        //dotAll模式
        // dot . 元字符: 代表除换行符之外的任意单个字符(其实就是加上模式修正符s,之后 . 能够匹配任意字符)
        let str = `<ul>
        <li>
            <a>肖生克的救赎</a>
            <p>上映时间:1994-09-10</p>
        </li>
        <li>
            <a>阿甘正传</a>
            <p>上映时间:1994-07-06</p>
        </li>
    </ul>`
            //声明正则  \s匹配任意空白字符
            // const reg = /<li>\s+<a>(.*?)<\/a>\s<p>(.*?)<\/p>/;
        const reg = /<li>.*?<a>(.*?)<\/a>.*?<p>(.*?)<\/p>/gs; //gs全局匹配 ， s单个匹配     //.*后面加上?禁止贪婪
        //执行匹配
        // const result = reg.exec(str);
        // console.log(result);
        let result;
        let data = [];
        while (result = reg.exec(str)) {
            console.log(result);
            data.push({
                title: result[1],
                time: result[2]
            })
        }
        console.log(data);
    </script>
</body>

</html>